package com.pet.petadoption.user.biz.imp;


import com.pet.petadoption.user.biz.UserBiz;
import com.pet.petadoption.user.entity.User;
import com.pet.petadoption.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserBizImpl implements UserBiz {
//    @Autowired
    @Resource
    UserMapper userMapper;

    @Override
    public User login(String account, String upwd) {
        return userMapper.userLogin(account,upwd);
    }

    @Override
    public List<User> findUsers(Integer index,Integer size,Integer status) {
        //        计算上一页最后一条数据
        int newIndex = (index-1)*size;
        Map<String,Object> map = new HashMap<>();
        map.put("index" ,newIndex);
        map.put("size",size);
        map.put("status",status);
        List<User>  userlist = userMapper.findUsers(map);
        return userlist;
    }

    @Override
    public Boolean addUser(User user) {
        System.out.println("register:"+user);
        return userMapper.addUser(user);
    }

    @Override
    public User findUserById(Integer id,Integer status) {
        return userMapper.findUserById(id,status);
    }

    @Override
    public List<User> findUserByUname(String info,Integer status) {
        return userMapper.findUseByUname(info,status);
    }

    @Override
    public Integer changeUserStatus(Integer id,Integer status) {
        return userMapper.changeUserStatus(id,status);
    }

    @Override
    public Integer delArr(String ids) {

        return userMapper.delArr(ids);
    }

    @Override
    public Integer updateUser(User user) {
        return userMapper.updateUser(user);
    }


}
